{extend name="platform/new_base" /}
{block name="resource"}

{/block}
{block name="main"}
<style>
    .label-danger a{padding-top:5px;}
    #editIcon-pa{
        position: absolute;
        right: 0;
        top: 10px;
        width: 18px;
        height: 18px;
        display: none;
    }
    .editChange{position: relative;cursor: pointer;}
    .editChange:hover #editIcon-pa {
        display: block;
    }
</style>
<form class="v-filter-container">
    <div class="filter-fields-wrap">
        <div class="filter-item clearfix">
            <div class="filter-item__field">
                <div class="v__control-group">
                    <label class="v__control-label">商品分类</label>
                    <div class="v__controls">
                        <input type="text" id="select_cname" name="select_cname" class="v__control_input J-selectCategory" placeholder="请选择分类" autocomplete="off">
                    </div>
                    <input type="hidden" id="category_id_1" name="category_id_1" autocomplete="off">
                    <input type="hidden" id="category_id_2" name="category_id_2" autocomplete="off">
                    <input type="hidden" id="category_id_3" name="category_id_3" autocomplete="off">
                    <input type="hidden" id="select_name_hidden" name="select_name_hidden" autocomplete="off">
                </div>
                <div class="v__control-group">
                    <label class="v__control-label">商品名称</label>
                    <div class="v__controls">
                        <input type="text" id="goods_name" class="v__control_input" placeholder="请输入商品名称" autocomplete="off">
                    </div>
                </div>
                {if($distributionStatus==1)}
                <div class="v__control-group">
                    <label class="v__control-label">分销信息</label>
                    <div class="v__controls">
                        <select class="v__control_input" id="is_distribution">
                            <option value="">全部</option>
                            <option value="1">参与分销</option>
                            <option value="2">不参与分销</option>
                            <option value="3">参与分销并设置商品独立规则</option>
                        </select>
                    </div>
                </div>
                {/if}
                {if($globalStatus==1 || $areaStatus==1 || $teamStatus==1)}
                <div class="v__control-group">
                    <label class="v__control-label">分红信息</label>
                    <div class="v__controls">
                        <select class="v__control_input" id="is_bonus">
                            <option value="">全部</option>
                            <option value="1">参与分红</option>
                            <option value="2">不参与分红</option>
                            <option value="3">参与分红并设置商品独立规则</option>
                        </select>
                    </div>
                </div>
                {/if}
                <div class="v__control-group">
                    <label class="v__control-label">商品标签</label>
                    <div class="v__controls">
                    	<div class="checkbox_three" style="margin-top: 6px;">
                            <label class="checkbox-inline"><input type="checkbox" name="label_list" value="1">推荐</label>
	                        <label class="checkbox-inline"><input type="checkbox" name="label_list" value="2">新品</label>
	                        <label class="checkbox-inline"><input type="checkbox" name="label_list" value="3">热卖</label>
	                        <label class="checkbox-inline"><input type="checkbox" name="label_list" value="4">促销</label>
	                        <label class="checkbox-inline"><input type="checkbox" name="label_list" value="5">包邮</label>
	                    </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="filter-item clearfix">
            <div class="filter-item__field">
                <div class="v__control-group">
                    <label class="v__control-label"></label>
                    <div class="v__controls">
                        <a class="btn btn-primary search"><i class="icon icon-search"></i>搜索</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<!-- page -->
<ul class="nav nav-tabs v-nav-tabs fs-12">
    <li role="presentation" {if !$type} class="active" {/if}><a href="{:__URL('PLATFORM_MAIN/goods/selfgoodslist')}" class="flex-auto-center">全部<br><span class="J-all"></span></a></li>
    <li role="presentation" {if condition="$type eq 1"} class="active" {/if}><a href="{:__URL('PLATFORM_MAIN/goods/selfgoodslist','type=1')}" class="flex-auto-center">出售中<br><span class="J-online"></span></a></li>
    <li role="presentation" {if condition="$type eq 2"} class="active" {/if}><a href="{:__URL('PLATFORM_MAIN/goods/selfgoodslist','type=2')}" class="flex-auto-center">仓库中<br><span class="J-offline"></span></a></li>
    <li role="presentation" {if condition="$type eq 3"} class="active" {/if}><a href="{:__URL('PLATFORM_MAIN/goods/selfgoodslist','type=3')}" class="flex-auto-center">已售聲<br><span class="J-soldout"></span></a></li>
    <li role="presentation" {if condition="$type eq 4"} class="active" {/if}><a href="{:__URL('PLATFORM_MAIN/goods/selfgoodslist','type=4')}" class="flex-auto-center">库存预警<br><span class="J-alarm"></span></a></li>
</ul>
<div class="mb-10 flex flex-pack-justify">
    <div class="">
        <a href="{:__URL('PLATFORM_MAIN/goods/addgoods')}" class="btn btn-primary"><i class="icon icon-add1"></i> 发布商品</a>
        <!--<a class="btn btn-default" href="javascript:void(0);">
            <label class="checkbox-inline">
                <input type="checkbox" id="checkAll">全选
            </label>
        </a>-->
        {if($goodhelperStatus==1)}
        <a href="{:__URL('PLATFORM_MAIN/addonslist/menu_addonslist?addons=goodImportHelper')}" class="btn btn-success" target="_blank">商品助手导入</a>
        {/if}
        <a class="btn btn-default online" href="javascript:void(0);">上架</a>
        <a class="btn btn-default outline" href="javascript:void(0);">下架</a>
        <a class="btn btn-default deleteGood" href="javascript:void(0);">删除</a>
    </div>
</div>
<table class="table v-table table-auto-center" id="selfGoodsList">
    <thead>
    <tr>
        <th><input type="checkbox" id="checkAll"></th>
        <th>ID</th>
        <th class="col-md-4">商品</th>
        <th>售价</th>
        <th>原价</th>
        <th>库存</th>
        <th>状态</th>
        <th class="col-md-2 pr-14 operationLeft">操作</th>
    </tr>
    </thead>
    <tbody id="goods_list">

    </tbody>
</table>
<input type="hidden" id="pageIndex">
<input type="hidden" id="type" value="{$type}">
<nav aria-label="Page navigation" class="clearfix">
    <ul id="page" class="pagination pull-right"></ul>
</nav>
<!-- page end  -->
{/block}




{block name="script"}
<script>
    require(['util','sotr-selector'],function(util){
        //全选
        util.initPage(LoadingInfo);
        function LoadingInfo(page_index) {
            var start_date = $("#startDate").val();
            var end_date = $("#endDate").val();
//      var state = $("#state").val();
            var goods_name = $("#goods_name").val();
            var category_id_1 = $("#category_id_1").val();
            var category_id_2 = $("#category_id_2").val();
            var category_id_3 = $("#category_id_3").val();
            var type = $("#type").val();
            var selectGoodsLabelId = $("#selectGoodsLabelId").val();
            var supplier_id = $("#supplier_id").val();
            var is_distribution = $("#is_distribution").val();
            var is_bonus = $("#is_bonus").val();
            var label_list = '';
            $("input[name ='label_list']:checked").each(function(){
            	label_list += $(this).val()+',';
            });
            $("#pageIndex").val(page_index);
            $.ajax({
                type: "post",
                url: "{:__URL('PLATFORM_MAIN/goods/selfgoodslist')}",
                data: {
                    "page_index": page_index,
                    "page_size": $("#showNumber").val(),
                    "start_date": start_date,
                    "end_date": end_date,
//              "state": state,
                    "goods_name": goods_name,
                    "category_id_1": category_id_1,
                    "category_id_2": category_id_2,
                    "category_id_3": category_id_3,
                    "selectGoodsLabelId": selectGoodsLabelId,
                    "supplier_id": supplier_id,
                    "is_distribution": is_distribution,
                    "is_bonus": is_bonus,
                    "label_list": label_list,
                    "type":type
                },
                success: function (data) {
                    var html = '';
                    var distributionStatus = {:json_encode($distributionStatus)};
                    var globalStatus = {:json_encode($globalStatus)};
                    var areaStatus = {:json_encode($areaStatus)};
                    var teamStatus = {:json_encode($teamStatus)};
                    if (data["data"].length > 0) {
                        for (var i = 0; i < data["data"].length; i++) {
                            if(data["data"][i]["goods_spec_format"].length<10){
                                html += '<tr data-goodsid="'+data["data"][i]["goods_id"]+'">';
                            }else{
                                html += '<tr data-goodsid="'+data["data"][i]["goods_id"]+'" title="规格商品暂不支持快速编辑价格">';
                            }
                            html += '<td>';
                            // html += '<input type="checkbox" value="\' + data["data"][i]["goods_id"] + \'" name="sub" data-state="\' + data["data"][i]["state"] + \'" type="checkbox">';
                            html += '<input value="' + data["data"][i]["goods_id"] + '" data-promotion_type="' + data["data"][i]["promotion_type"] + '" name="sub" data-state="' + data["data"][i]["state"] + '" type="checkbox">';
                            html += '</td>';
                            html += '<td>' + data["data"][i]["goods_id"] + '</td>';
                            html += '<td class="picword_td show_goodsname editChange">';
                            html += '<div class="media text-left ">';
                            html += '<div class="editIcon-pa" id="editIcon-pa">';
                            html += '<i class="icon icon-edit" data-name="'+data["data"][i]["goods_name"]+'"></i>';
                            
                            html += '</div>';
                            html += '<div class="media-left"><p><img src="' + __IMG(data["data"][i]["pic_cover"]) + '" style="width:60px;height:60px;"></p></div>';
                            html += '<div class="media-body break-word">';
                            html += '<div class="line-2-ellipsis line-title">';
                            html += '<a class="a-goods-title" href="' + __URLS('SHOP_MAIN/goods/goodsinfo&goodsid=' + data["data"][i]["goods_id"]) + '" target="_blank">' + data["data"][i]["goods_name"] + '</a>';
                            html += '<textarea class="editTextarea edit_goods_name" value="'+data["data"][i]  ["goods_name"]+'" style="height:40px;width: 300px;display: none">'+data["data"][i]["goods_name"]+'</textarea>';
                            html += '</div>';
                            html += '<div class="small-muted line-2-ellipsis"> </div>';
                            html += '</div>';
                            html += '</div>';
                            html += '</td>';
                            if(data["data"][i]["goods_spec_format"].length<10){
                                html += '<td class="goodsEdit">';
                            }else{
                                html += '<td>';
                            }
                            html += '<span class="editSpan">￥' + data["data"][i]["price"] + '</span>';
                            html += '<input type="text" class="edit_price  editInput3" value="' + data["data"][i]["price"] + '" style="width: 30%;display: none">';
                            if(data["data"][i]["goods_spec_format"].length<10){
                                html += '<span class="editIcon show_promotion_price"><i class="icon icon-edit"></i></span>';
                            }
                            else{
                                html += '<span class="editIcon1"><i class="icon icon-edit"></i></span>';
                            }
                            html += '</td>';

                            if(data["data"][i]["goods_spec_format"].length<10){
                                html += '<td class="goodsEdit">';
                            }else{
                                html += '<td>';
                            }
                            html += '<span class="editSpan">￥' + data["data"][i]["market_price"] + '</span>';
                            html += '<input type="text" class="edit_market_price editInput3" value="' + data["data"][i]["market_price"] + '" style="width: 30%;display: none">';
                            if(data["data"][i]["goods_spec_format"].length<10){
                                html += '<span class="editIcon show_price"><i class="icon icon-edit"></i></span>';
                            }
                            else{
                                html += '<span class="editIcon1"><i class="icon icon-edit"></i></span>';
                            }

                            html += '</td>';
                            if(data["data"][i]["goods_spec_format"].length<10){
                                html += '<td class="goodsEdit">';
                            }else{
                                html += '<td>';
                            }
                            html += '<span class="editSpan">' + data["data"][i]["stock"] + '</span>';
                            html += '<input type="text" class="edit_stock editInput3" value="' + data["data"][i]["stock"] + '" style="width: 30%;display: none">';
                            if(data["data"][i]["goods_spec_format"].length<10){
                                html += '<span class="editIcon show_stock"><i class="icon icon-edit"></i></span>';
                            }
                            else{
                                html += '<span class="editIcon1"><i class="icon icon-edit"></i></span>';
                            }
                            html += '</td>';
                            html += '<td>';
                            if (data["data"][i]["state"] == 1) {
                                html += '<a class="label label-success outline" data-id="'+data["data"][i]["goods_id"]+'" href="javascript:void(0);" >上架</a>';
                            }else{
                                html += '<a class="label label-danger online" data-id="'+data["data"][i]["goods_id"]+'" href="javascript:void(0);" >下架</a>';
                            }
                            html += '</td>';

                            html += '<td class="operationLeft fs-0">';
                            html += '<a class="btn-operation" href="javascript:;" data-promotion_type="' + data["data"][i]["promotion_type"] + '" data-promotion_name="' + data["data"][i]["promotion_name"] + '" data-goods_id="'+data["data"][i]["goods_id"]+'" id="goods_edit">编辑</a>';
                            // html +='<a class="btn-operation copy" href="javascript:void(0);"  data-clipboard-text="' + __URLS('SHOP_MAIN/goods/goodsinfo&goodsid=' + data["data"][i]["goods_id"]) + '">复制链接</a>';
                            html +='<a class="btn-operation link-pr" data-goods_id="' + data["data"][i]["goods_id"] + '" href="javascript:void(0);" > <span>链接</span> <div class="link-pos"> </div> </a>';
                            html +='<a class="btn-operation deleteGood text-red1" data-id="' + data["data"][i]["goods_id"] + '" data-promotion_type="' + data["data"][i]["promotion_type"] + '" data-promotion_name="' + data["data"][i]["promotion_name"] + '" href="javascript:void(0)">删除</a>';

                            util.copy();
                            html += '</td>';
                            html += '</tr>';
							html += '<tr class="title-tr"><td colspan="8" class="text-right" style="border-top:0;">';
							if(data["data"][i]["is_distribution"]==1 && data["data"][i]["distribution_rule"]!=1 && distributionStatus==1){
								html += '<span class="label label-skyBlue">参与分销</span>&nbsp;-&nbsp;';
							}
							if(data["data"][i]["is_distribution"]==1 && data["data"][i]["distribution_rule"]==1 && distributionStatus==1){
								html += '<span class="label label-skyBlue">参与分销并设置商品独立规则</span>&nbsp;-&nbsp;';
							}
							if(((data["data"][i]["is_bonus_global"]==1 && globalStatus==1) || (data["data"][i]["is_bonus_area"]==1 && areaStatus==1) || (data["data"][i]["is_bonus_team"]==1 && teamStatus==1)) && data["data"][i]["bonus_rule"]!=1){
								html += '<span class="label label-skyBlue">参与分红</span>&nbsp;-&nbsp;';
							}
							if(((data["data"][i]["is_bonus_global"]==1 && globalStatus==1) || (data["data"][i]["is_bonus_area"]==1 && areaStatus==1) || (data["data"][i]["is_bonus_team"]==1 && teamStatus==1)) && data["data"][i]["bonus_rule"]==1){
								html += '<span class="label label-skyBlue">参与分红并设置商品独立规则</span>&nbsp;-&nbsp;';
							}
							if(data["data"][i]["is_recommend"]==1){
								html += '<a href="javascript:void(0);" class="label label-red labels" data-label="recommend" data-id="'+data["data"][i]["goods_id"]+'">推荐</a>&nbsp;-&nbsp;';
							}else{
								html += '<a href="javascript:void(0);" class="label label-grey labels" data-label="recommend" data-id="'+data["data"][i]["goods_id"]+'">推荐</a>&nbsp;-&nbsp;';
							}
							if(data["data"][i]["is_new"]==1){
								html += '<a href="javascript:void(0);" class="label label-red labels" data-label="new" data-id="'+data["data"][i]["goods_id"]+'">新品</a>&nbsp;-&nbsp;';
							}else{
								html += '<a href="javascript:void(0);" class="label label-grey labels" data-label="new" data-id="'+data["data"][i]["goods_id"]+'">新品</a>&nbsp;-&nbsp;';
							}
							if(data["data"][i]["is_hot"]==1){
								html += '<a href="javascript:void(0);" class="label label-red labels" data-label="hot" data-id="'+data["data"][i]["goods_id"]+'">热卖</a>&nbsp;-&nbsp;';
							}else{
								html += '<a href="javascript:void(0);" class="label label-grey labels" data-label="hot" data-id="'+data["data"][i]["goods_id"]+'">热卖</a>&nbsp;-&nbsp;';
							}
							if(data["data"][i]["is_promotion"]==1){
								html += '<a href="javascript:void(0);" class="label label-red labels" data-label="promotion" data-id="'+data["data"][i]["goods_id"]+'">促销</a>&nbsp;-&nbsp;';
							}else{
								html += '<a href="javascript:void(0);" class="label label-grey labels" data-label="promotion" data-id="'+data["data"][i]["goods_id"]+'">促销</a>&nbsp;-&nbsp;';
							}
							if(data["data"][i]["is_shipping_free"]==1){
								html += '<a href="javascript:void(0);" class="label label-red labels" data-label="shipping_free" data-id="'+data["data"][i]["goods_id"]+'">包邮</a>';
							}else{
								html += '<a href="javascript:void(0);" class="label label-grey labels" data-label="shipping_free" data-id="'+data["data"][i]["goods_id"]+'">包邮</a>';
							}
							html += '</td></tr>';
                        }
                    } else {
                        html += '<tr align="center"><td colspan="7" class="h-200">暂无符合条件的数据记录</td></tr>';
                    }
                    $("#goods_list").html(html);
                    util.tips();
                    var totalpage = $("#page_count").val();
                    if (totalpage == 1) {
                        changeClass("all");
                    }
                        $('#page').paginator('option', {
                        totalCounts: data['total_count']  // 动态修改总数
                    });
                    $("#pageNumber").append(html);
                    goodListEdit();
                }
            });
        }
        $("#checkAll").on('click',function(){
            $("#selfGoodsList input[type = 'checkbox']").prop("checked", this.checked);
        })

        //搜索
        $('.search').on('click',function(){
            util.initPage(LoadingInfo);
        });
        //分类
        $('body').on('click','.J-selectCategory', function () {
            setCategory();
        });
        function setCategory(){
            var url = "{:__URL('PLATFORM_MAIN/goods/selectcategory')}";
            util.confirm('选择分类','url:'+url, function () {
                var cid1 = this.$content.find('#selected_c1').val();
                var cid2 = this.$content.find('#selected_c2').val();
                var cid3 = this.$content.find('#selected_c3').val();
                var cname = this.$content.find('#selected_cn').val();
                $("#category_id_1").val(cid1);
                $("#category_id_2").val(cid2);
                $("#category_id_3").val(cid3);
                $("#select_cname").val(cname);
                $("#select_name_hidden").val(cname);
            },'large');
        }
        $('body').on('click','#goods_edit',function(){
            var promotion_type = $(this).data('promotion_type');
            var promotion_name = $(this).data('promotion_name');
            if(promotion_name === ''){
                promotion_name = '活动';
            }
            var goods_id = $(this).data('goods_id');
            // if(!promotion_type){
            //     window.location.href = __URL('PLATFORM_MAIN/goods/addgoods?goods_id='+goods_id);
            // }else{
            //     util.message('该商品参加了' + promotion_name + '，不能编辑',"danger");
            // }
            // by sgw 这个不判断，进入里面判断
            window.location.href = __URL('PLATFORM_MAIN/goods/addgoods?goods_id='+goods_id);
            //'+__URL('PLATFORM_MAIN/goods/addgoods?goods_id='+data["data"][i]["goods_id"])+'
        })
        //删除商品02081650907

        $("body").on('click','.deleteGood',function(){
            var goodsId = [];
            if($(this).data('id')&&!isNaN($(this).data('id'))){
                var promotion_type = $(this).data('promotion_type');
                var promotion_name = $(this).data('promotion_name');
                if(promotion_name === ''){
                    promotion_name = '活动';
                }
                if(promotion_type){
                    util.message('该商品参加了' + promotion_name + '，不能删除',"danger");
                    return false;
                }
                goodsId.push($(this).data('id'));
            }else{
                var has_promote = false;
                $("#selfGoodsList input[type = 'checkbox']:checked").each(function(){
                    if(!$(this).data('promotion_type')){
                        if (!isNaN($(this).val())) {
                            goodsId.push($(this).val());
                        }
                    }else{
                        $(this).attr('checked',false);
                        has_promote = true;
                    }
                });
            }
            
            if(goodsId.length==0){
                util.message('请选择需要删除的商品','danger');
                return false;
            }
            util.alert('是否删除此商品？',function(){
                //util.message('删除的商品id='+goodsId)
                $('#checkAll').prop('checked',false);
                $.ajax({
                    type: "post",
                    url: "{:__URL('PLATFORM_MAIN/goods/deletegoods')}",
                    data: {"goods_ids": goodsId.toString()},
                    dataType: "json",
                    async : true,
                    success : function(data) {
                        if (data["code"] > 0) {
                            util.message(data["message"],'success',LoadingInfo($('#pageIndex').val()));
                        }else{
                            util.message(data["message"],'danger',LoadingInfo($('#pageIndex').val()));
                        }
                    }
                })

            })

        })


        //快速编辑
        function goodListEdit(){

            //售价
            $(".goodsEdit").on("click",".show_promotion_price",function(){
                $(this).siblings(".editSpan").hide();
                $(this).siblings(".edit_price").show();
                $(this).siblings(".edit_price").focus();
                //  $(this).addClass("visible");
            });
            $(".goodsEdit").on("blur",".edit_price",function(){
                var id = $(this).parent().parent().attr("data-goodsid");
                var price = Number($(this).val());
                var value = $(this).prev();
                $(this).siblings(".editSpan").show();
                $(this).hide();
                $(this).siblings(".editIcon").removeClass("visible");
                $.ajax({
                    type: "post",
                    data:{
                        "id":id,
                        "price":price,
                        "market_price":0,
                        "stock":0

                    },
                    url: "{:__URL('PLATFORM_MAIN/goods/quikly_edit')}",
                    success: function (data) {
                        if(data['code']){
                            util.message(data['message'],'danger');
                        }else{
                            value.html("￥"+price+".00");
                        }
                    }
                })
            })

            //市场价
            $(".goodsEdit").on("click",".show_price",function(){
                $(this).siblings(".editSpan").hide();
                $(this).siblings(".edit_market_price").show();
                $(this).siblings(".edit_market_price").focus();
                //  $(this).addClass("visible");
            });
            $(".goodsEdit").on("blur",".edit_market_price",function(){
                var id = $(this).parent().parent().attr("data-goodsid");
                var market_price = Number($(this).val());
                var value = $(this).prev();
                $(this).siblings(".editSpan").show();
                $(this).hide();
                $(this).siblings(".editIcon").removeClass("visible");
                $.ajax({
                    type: "post",
                    data:{
                        "id":id,
                        "price":0,
                        "market_price":market_price,
                        "stock":0
                    },
                    url: "{:__URL('PLATFORM_MAIN/goods/quikly_edit')}",
                    success: function (data) {
                        if(data['code']){
                            util.message(data['message'],'danger');
                        }else{
                            value.html(market_price);
                        }
                    }
                })
            })

            //库存
            $(".goodsEdit").on("click",".show_stock",function(){
                $(this).siblings(".editSpan").hide();
                $(this).siblings(".edit_stock").show();
                $(this).siblings(".edit_stock").focus();
                //  $(this).addClass("visible");
            });
            $(".goodsEdit").on("blur",".edit_stock",function(){
                var id = $(this).parent().parent().attr("data-goodsid");
                var stock = Number($(this).val());
                var value = $(this).prev();
                $(this).siblings(".editSpan").show();
                $(this).hide();
                $(this).siblings(".editIcon").removeClass("visible");
                $.ajax({
                    type: "post",
                    data:{
                        "id":id,
                        "price":0,
                        "market_price":0,
                        "stock":stock
                    },
                    url: "{:__URL('PLATFORM_MAIN/goods/quikly_edit')}",
                    success: function (data) {
                        if(data['code']){
                            util.message(data['message'],'danger');
                        }else{
                            value.html(stock);
                        }
                    }
                })
            })


            //商品名
            $(".editChange").on("click",function(){
                $(this).children(".media").find(".line-title").children("a").hide().siblings(".edit_goods_name").show();
                $(this).children(".media").find(".line-title").children("a").hide().siblings(".edit_goods_name").focus();
                //  $(this).addClass("visible");
            });
            $(".editChange").on("blur",".edit_goods_name",function(){
                var id = $(this).parent().parent().parent().parent().parent().attr("data-goodsid");
                var name = $(this).val();
                $(this).hide();
                $(this).parents(".media").find(".line-title").children("a").show();
                $.ajax({
                    type: "post",
                    data:{
                        "id":id,
                        "goods_name":name,
                    },
                    url: "{:__URL('PLATFORM_MAIN/goods/quikly_edit')}",
                    success: function () {
                    }
                })
                $(this).prev().html(name);
            })
        }

        // 上架

        $("body").on('click', '.online', function(){
            var goodsId = [];
            if($(this).data('id')&&!isNaN($(this).data('id'))){
                goodsId.push($(this).data('id'));
            }else{
                $("#selfGoodsList input[type = 'checkbox']:checked").each(function(){
                    if (!isNaN($(this).val())) {
                        goodsId.push($(this).val());
                    }
                })
            }
            if(goodsId.length==0){
                util.message('请选择需要上架的商品','danger');
                return false;
            }
            $('#checkAll').prop('checked',false);
            $.ajax({
                type: "post",
                url: "{:__URL('PLATFORM_MAIN/goods/ModifyGoodsOnline')}",
                data: {"goods_ids": goodsId.toString()},
                dataType: "json",
                async : true,
                success : function(data) {
                    if (data["code"] > 0) {
                        util.message(data["message"],'success',LoadingInfo($('#pageIndex').val()));
                    }else{
                        util.message(data["message"],'danger',LoadingInfo($('#pageIndex').val()));
                    }
                }
            })
        })


        // 下架
        $('body').on('click', '.outline', function(){
            var goodsId = [];
            if($(this).data('id')&&!isNaN($(this).data('id'))){
                goodsId.push($(this).data('id'));
            }else{
                $("#selfGoodsList input[type = 'checkbox']:checked").each(function(){
                    if (!isNaN($(this).val())) {
                        goodsId.push($(this).val());
                    }
                })
            }
            
            if(goodsId.length==0){
                util.message('请选择需要下架的商品','danger');
                return false;
            }
            $('#checkAll').prop('checked',false);
            $.ajax({
                type: "post",
                url: "{:__URL('PLATFORM_MAIN/goods/ModifyGoodsOffline')}",
                data: {"goods_ids": goodsId.toString()},
                dataType: "json",
                async : true,
                success : function(data) {
                    if (data["code"] > 0) {
                        util.message(data["message"],'success',LoadingInfo($('#pageIndex').val()));
                    }else{
                        util.message(data["message"],'danger',LoadingInfo($('#pageIndex').val()));
                    }
                }
            })

        })

        getgoodscount();
        //获取商品各种状态的数量
        function getgoodscount(){
            $.ajax({
                type: "post",
                url: "{:__URL('PLATFORM_MAIN/goods/getgoodscount')}",
                success: function (data) {
                    $('.J-all').html('('+data.all+')');
                    $('.J-online').html('('+data.sale+')');
                    $('.J-offline').html('('+data.shelf+')');
                    $('.J-soldout').html('('+data.soldout+')');
                    $('.J-alarm').html('('+data.alarm+')');
                }
            })
        }
		//修改标签
        $('body').on('click', '.labels', function(){
            var label =  $(this).data('label');
            var id =  $(this).data('id');
            $.ajax({
                type: "post",
                url: "{:__URL('PLATFORM_MAIN/goods/editLabel')}",
                data: {"label": label,"goods_id":id},
                dataType: "json",
                async : true,
                success : function(data) {
                    if (data["code"] > 0) {
                        util.message(data["message"],'success',LoadingInfo($('#pageIndex').val()));
                    }else{
                        util.message(data["message"],'danger',LoadingInfo($('#pageIndex').val()));
                    }
                }
            })
        })
        //当经过链接的时候再加载二维码
        $('body').on('mouseover', '.link-pr', function(){
            if($(this).attr('mark')){
                return;
            }
            var goods_id = $(this).data('goods_id');
            var html = '<div class="link-arrow">' +
            ' <form class="form-horizontal"> ';
            if('{$wap_status}' == 1){
                html += '<div class="form-group"> <label class="col-md-2 control-label">手机端</label> <div class="col-md-10"> <div class="input-group"> <input class="form-control" type="text" disabled value="' + __URLS('SHOP_MAIN/wap/goods/detail/' + goods_id) + '"> <span class="input-group-btn btn btn-primary bbllrr0 copy" data-clipboard-text="' + __URLS('SHOP_MAIN/wap/goods/detail/' + goods_id) + '">复制链接</span> </div> </div> </div>';
            }

            if('{$is_pc_use}' == 1){
                html += ' <div class="form-group"> <label class="col-md-2 control-label">电脑端</label> <div class="col-md-10"> <div class="input-group"> <input class="form-control" type="text" disabled value="' + __URLS('SHOP_MAIN/goods/goodsinfo&goodsid=' + goods_id) + '"> <span class="input-group-btn btn btn-primary bbllrr0 copy" data-clipboard-text="' + __URLS('SHOP_MAIN/goods/goodsinfo&goodsid=' + goods_id) + '">复制链接</span> </div> </div> </div> ';
            }
            if('{$wap_status}' == 1) {
                html += '</form> ' +
                    '<div class="flex link-flex"> ' +
                    '<div class="flex-1"> <div class="mb-04"><img src="' + __URL(PLATFORMMAIN + '/goods/getGoodsDetailQr') + '?goods_id=' + goods_id + '&qr_type=1&wap_path=/wap/goods/detail/" style="width: 100px;height: 100px"></div> <p>(手机端二维码)</p> </div> ';
            }
            if('{$is_minipro}' == 1){
                html += '<div class="flex-1"> <div class="mb-04"><img src="'+ __URL(PLATFORMMAIN + '/goods/getGoodsDetailQr') +'?goods_id='+ goods_id +'&qr_type=2&mp_path=pages/goods/detail/index" style="width: 100px;height: 100px"></div> <p>(小程序二维码)</p> </div>';
            }
            html += ' </div> </div>';
            $(this).find('.link-pos').html(html);
            $(this).attr('mark', true);
            mark = true;
        })
    })

</script>
{/block}
